import { OnInit, Component, ViewChild } from '@angular/core';
import { ComprehensiveEvaluationListComponent } from './comprehensive-evaluation-list.component';
import { SettingsService } from '@delon/theme';
import { StudentService } from 'src/app/project/service/icm/icm-system-user/student/student.service';
import { StudentDTO } from 'src/app/project/model/icm/icm-system-user/student/student.dto';
import { NzModalService } from 'ng-zorro-antd';

@Component({
  selector: 'app-comprehensive-evaluation-view',
  templateUrl: './comprehensive-evaluation-view.component.html',
  styles: [],
})
export class ComprehensiveEvaluationViewComponent implements OnInit {
  constructor(private settingService: SettingsService, private modalService: NzModalService) {}

  @ViewChild('comprehensiveEvaluationListComponent', { static: false })
  comprehensiveEvaluationListComponent: ComprehensiveEvaluationListComponent;

  /**
   * 条件查询参数
   */
  queryParams = {
    academyName: null,
    professionName: null,
    className: null,
    classId: null,
    studentName: null,
    studentCode: null,
    year: null,
    compAssessProcessStatus: null,
  };

  /**
   * 当前登录学生
   */
  student: StudentDTO = {
    id: null,
    code: null,
    name: null,
    gender: null,
    grade: null,
    isClassEvaluationAdmin: null,
    studentDetail: null,
    studyYears: null,
    joinTime: null,
    academyId: null,
    academyName: null,
    professionId: null,
    professionName: null,
    classId: null,
    className: null,
  };
  studentId = null;

  /**
   * 刷新
   */
  reflesh() {
    this.comprehensiveEvaluationListComponent.loadData();
  }

  /**
   * 查询
   */
  onSearch() {
    this.comprehensiveEvaluationListComponent.loadData();
  }

  /**
   * 班级综测管理员和学生身份切换
   */
  switch() {
    const idenfty = !this.settingService.user.isClassEvaluationAdmin ? '班级综测管理员' : '学生';
    const info = !this.settingService.user.isClassEvaluationAdmin ? '班级' : '学生';
    this.modalService.confirm({
      nzTitle: '切换身份',
      nzContent: `<p>切换为  ${idenfty}  以查看  ${info}综合测评</p>`,
      nzOnOk: () => {
        this.settingService.user.isClassEvaluationAdmin = !this.settingService.user.isClassEvaluationAdmin;
        this.queryParams.compAssessProcessStatus = 'CLASS_ASSESSMENT';
        this.onSearch();
      },
    });
  }
  /**
   * 查看公示栏
   */
  noticeBoard() {
    this.modalService.confirm({
      nzTitle: '查看公示栏',
      nzContent: `<p>查看已公示的学生综测数据，处理未审结数据</p>`,
      nzOnOk: () => {
        this.queryParams.compAssessProcessStatus = 'DONE_ASSESSMENT';
        this.onSearch();
      },
    });
  }
  /**
   * 返回年级复审
   */
  gradeReview() {
    this.modalService.confirm({
      nzTitle: '返回年级复审',
      nzContent: `<p>查看年级复审的学生综测数据，处理年级复审数据</p>`,
      nzOnOk: () => {
        this.queryParams.compAssessProcessStatus = 'GRADE_REVIEW';
        this.onSearch();
      },
    });
  }
  /**
   * 查看审结
   */
  closeReview() {
    this.modalService.info({
      nzTitle: '查看审结',
      nzContent: `<p>查看学生综测年级复审的审结结果</p>`,
      nzOnOk: () => {
        this.queryParams.compAssessProcessStatus = 'DONE_CLOSE';
        this.onSearch();
      },
    });
  }
  /**
   * 重置表单
   */
  onResetForm() {
    this.queryParams.year = null;
    this.queryParams.compAssessProcessStatus = null;
  }

  ngOnInit() {
    if (this.settingService.user.isStudent) {
      this.queryParams.classId = this.settingService.user.isClassEvaluationAdmin
        ? this.settingService.user.classId
        : null;
      this.queryParams.compAssessProcessStatus = this.settingService.user.isClassEvaluationAdmin
        ? 'CLASS_ASSESSMENT'
        : null;
    } else {
      this.queryParams.academyName = this.settingService.user.academyName;
      this.queryParams.compAssessProcessStatus = 'GRADE_REVIEW';
    }
  }
}
